package com.zx.cloud.controller;

import io.swagger.annotations.ApiOperation;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.google.gson.Gson;
import com.zx.cloud.ApiVersion;
import com.zx.cloud.RequestLogging;
import com.zx.cloud.common.filter.CurrentUserId;
import com.zx.cloud.domain.Shop;
import com.zx.cloud.model.response.ObjectDataResponse;
import com.zx.cloud.model.response.Response;
import com.zx.cloud.service.ClientInfoService;
import com.zx.cloud.service.LogService;
import com.zx.cloud.service.ShopService;
import com.zx.cloud.util.Page;
import com.zx.cloud.utils.Sequence;

/**
 * @Description:
 *
 * @author       Yan Weiwei
 * @Create Time: 2017年10月30日上午11:30:15
 */
@RestController
@RequestMapping(value = ApiVersion.PROVIDER_V1_PREFIX+"/shop")
public class ShopController {
	
	@Autowired
	private ClientInfoService clientInfoService;

	@Autowired
	private ShopService shopService;
	@Autowired
	private LogService logService;
	
	@RequestLogging
	@ApiOperation(value = "查询商户列表信息" , notes = "查询商户列表信息")
	@RequestMapping(value = "/queryClientInfo", method = RequestMethod.POST)
	@ResponseBody
	public Response queryClientInfo(@RequestBody Shop shop){
		Gson gson=new Gson();
		shop.setDel(0);
		Page<Shop> datas=shopService.page(shop);
		logService.addLog(null, "查询商户列表", 0);
		System.out.println("----------------------------"+gson.toJson(datas));
		return new ObjectDataResponse<Page<Shop>>(datas);
	}
	
	
	
	// 添加公告信息
	@RequestLogging
	@ApiOperation(value = "添加商户" , notes = "添加商户")
	@RequestMapping(value = "addClientInfo", method = RequestMethod.POST)
	@ResponseBody
	public Response addClientInfo(HttpServletRequest request, @RequestBody Shop shop) {
		Gson gson=new Gson();
		shop.setIdString(Sequence.nextId());
		shop.setType(0);
		shop.setSearchnumber(100);
		shop.setDel(0);
		int success = shopService.insert(shop);
		return new ObjectDataResponse<Integer>(success);
	}
	
	
	// 删除公告信息
		@RequestLogging
		@ApiOperation(value = "删除商户" , notes = "删除商户")
		@RequestMapping(value = "deletClientInfo", method = RequestMethod.POST)
		@ResponseBody
		public Response deletClientInfo(@CurrentUserId Long userId,
				HttpServletRequest request, @RequestBody Shop shop) {
			shop.setDel(1);
			int success = shopService.update(shop);
			return new ObjectDataResponse<Integer>(success);
		}
	
	
}
